class leftTree extends eui.Component implements  eui.UIComponent {
	listtree:eui.List
    scroller:eui.Scroller
	sourceArr:any[] = [];
	myCollection:eui.ArrayCollection
	public constructor() {
		super();
	}

	protected partAdded(partName:string,instance:any):void
	{
		super.partAdded(partName,instance);
	}


	protected childrenCreated():void
	{
		super.childrenCreated();
		var shap:egret.Shape=new egret.Shape
		shap.graphics.beginFill(0xF0F0F0,0.5);
		shap.graphics.lineStyle(1)
		shap.graphics.drawRect(0,0,this.width,this.height);
		shap.graphics.endFill();
		this.addChildAt(shap,0)
		this.scroller.viewport=this.listtree
        /*for (var i:number = 1; i < 5; i++){
            //给数据中添加一个含有"label"属性的对象
            this.sourceArr.push({labeltx:"item"+i,pic:"st_IconReturn_00.tpl(st 图标返回_00.tpl)_爱给网_aigei_com_png"});
        }
        //用ArrayCollection包装*/
        this.myCollection= new eui.ArrayCollection(this.sourceArr);
       
        this.listtree.dataProvider= this.myCollection;
        this.listtree.itemRenderer = leftTreeRenderer;
		this.beginlisten();
       
   
	}
	 private onChange(e:eui.PropertyEvent):void{
        //获取点击消息
		//this.sourceArr.push({label:"item"+6});
		// console.log("parent")
		CMainEditor.editor.collitionchangetoobject()
	    let a=CBASE_MANAGE.getCBASE_MANAGE.getanyoneByname(this.listtree.selectedItem.labeltx)
		CMainEditor.editor.goal=a
	    CCollitionEditor.editor.goal=undefined;
	    if(CMainEditor.editor.goal.judge.length)CCollitionEditor.editor.goal=CMainEditor.editor.goal.judge[0]
		else if(CMainEditor.editor.goal.unjudge.length)CCollitionEditor.editor.goal=CMainEditor.editor.goal.unjudge[0]
		CMainEditor.editor.rightchangeTOcobject();
    }
	public changeseletByobjectname(name:string)
	{
        for(let a=0;a<this.myCollection.length;a++)
		{
			if(this.myCollection.getItemAt(a).labeltx==name)
			{
				this.listtree.selectedItem=this.myCollection.getItemAt(a);
			}
		}
	}
	public changeseletBycollision(collision:CCOLLISION)
	{
		let name=collision.parent.objName

		for(let a=0;a<this.myCollection.length;a++)
		{
			if(this.myCollection.getItemAt(a).labeltx==name)
			{
				this.listtree.selectedItem=this.myCollection.getItemAt(a);
			}
		}
	}
	public addlist(name:string,imageresouce:string)
	{
		if(imageresouce.split("/")[1]=="json")
		this.myCollection.addItem({labeltx:name,pic:imageresouce.split("/")[1]+"_png"});


		this.myCollection.addItem({labeltx:name,pic:imageresouce})
	}
	public clearALL()
	{
		this.myCollection.removeAll();
	}
	public removelist(name:string)
	{
		for(let a=0;a<this.myCollection.length;a++)
		{
			if(this.myCollection.getItemAt(a).labeltx==name)
			{
				this.myCollection.removeItemAt(a);
				break;
			}
		}
		
	}
	public objnamechange(prvname:string,nowname:string)
	{
		for(let a=0;a<this.myCollection.length;a++)
		{
			if(this.myCollection.getItemAt(a).labeltx==prvname)
			{
				this.myCollection.getItemAt(a).labeltx=nowname;
			}
		}
	}
	public collisionnamechange()
	{
		this.myCollection.refresh()
	}
	public stoplisten()
	{
      this.listtree.removeEventListener(eui.ItemTapEvent.ITEM_TAP,this.onChange,this);
	}
	public beginlisten()
	{
		this.listtree.addEventListener(eui.ItemTapEvent.ITEM_TAP,this.onChange,this);
	}
	
}
    class leftTreeRenderer extends eui.ItemRenderer {
		buttonpic:eui.Image
		headpic:eui.Image
		labeltx:eui.Label
        group:eui.Group
		child:collition_child[]=[]
		closeoropen:boolean=false;
        public constructor(){
            super();
            //自定义的 ItemRenderer
			this.skinName="Myitemrender"
            this.touchChildren = true;
            
        }
		protected childrenCreated():void{
			super.childrenCreated()
			this.buttonpic.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onclick,this);
		}
		protected onclick(e:egret.TouchEvent)
	    {
			//实现树状结构
			if(this.closeoropen)
			{
			   CMainEditor.editor.objectchangetocollition();
              this.treeopen()
			}
			else 
			{
				CMainEditor.editor.collitionchangetoobject();
				this.treeRetract()
			}
			this.closeoropen=!this.closeoropen

		}

		private treeRetract()
	    {
		   //console.log("child")
		 
           for(let a=0;a<this.child.length;a++)
				{
					//this.child[a].removeEventListener(egret.TouchEvent.TOUCH_TAP,this.collitionclick,this)
					this.group.removeChild(this.child[a])
					this.height-=this.child[a].height+5
					this.group.height-=this.child[a].height+5
				}
				this.child=[];
		}
        private treeopen()
		{
			// console.log("child")
              let a=CBASE_MANAGE.getCBASE_MANAGE.getanyoneByname(this.data.labeltx)
			  if(a==undefined)return
			   //console.log("change4")
			 
			  //读取当前对象的碰撞盒信息
			  let colldata=a.getcollitiondata();
			  for(let b=0;b<colldata.length;b++)
			  {
				  let collitionchild=new collition_child
				  this.group.addChild(collitionchild)
				   collitionchild.y=this.height+5
			      this.height+=collitionchild.height+5
			      this.group.height+=collitionchild.height+5
				  this.child.push(collitionchild)
				
				  //collitionchild.addEventListener(egret.TouchEvent.TOUCH_TAP,this.collitionclick,this);
				
				  collitionchild.setup(colldata[b].judge,colldata[b].name,colldata[b].judgeytpe)
				  collitionchild.setparent(a);
			  }
		}
        protected dataChanged():void{
			
            this.treeRetract()
		
			this.treeopen()
            
        }
    }